package top.yuhaitao.core.controller;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.yuhaitao.core.controller.RequestModel.RequestTest;
import top.yuhaitao.core.pojo.ProductCategory;
import top.yuhaitao.core.pojo.ProductInfo;
import top.yuhaitao.core.service.ProductCategoryService;
import top.yuhaitao.core.service.ProductInfoService;
import top.yuhaitao.core.service.SecondKillSevice;
import top.yuhaitao.core.vo.ProductInfoVO;
import top.yuhaitao.core.vo.ProductVO;
import top.yuhaitao.core.vo.ResultVO;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 买家商品
 *
 * @author ht.yu
 */

@RestController
@RequestMapping("/secondKill")
public class SecondKillController {

    private static final String productId = "25a86388-001c-4163-a925-edfe5b3d8628";

    @Resource
    private SecondKillSevice secondKillSevice;

    @RequestMapping("/index")
    @ResponseBody
    public String index() {
        return "index";
    }

    @GetMapping("/getCountkill")
    @ResponseBody
    public ProductInfo getCountkill() {
        return secondKillSevice.querySeconedKillProductInfo(productId);
    }

    @RequestMapping("/kill")
    @ResponseBody
    public RequestTest kill(@RequestBody RequestTest request) {
        System.out.println("request : " + request);
        System.out.println("name : " + request.getName());
        System.out.println("sex : " + request.getSex());
        System.out.println("age : " + request.getAge());
        secondKillSevice.seconedKill(productId);
        return request;
    }

}
